package com.grp6.game.chess;

import java.util.ArrayList;
import java.util.List;

import com.grp6.game.chess.player.ChessComputerPlayer;
import com.grp6.game.chess.player.ChessHumanPlayer;
import com.grp6.game.chess.player.IChessPlayer;
import com.grp6.game.settings.IPreferences;
import com.grp6.game.ui.platform.IAbstractUIPlatformFactory;
import com.grp6.game.ui.platform.IDialog;
import com.grp6.game.ui.platform.IQuestionValidator;

public class ChessPreferences implements IPreferences, IQuestionValidator{

	private final IAbstractUIPlatformFactory ui_factory;
	private List<Class<? extends IChessPlayer>> player_types = new ArrayList<Class<? extends IChessPlayer>>();
	
	public static final String Q_WHITE_MODE = 
		"White pieces Computer/Human [C/H]";
	
	public static final String Q_BLACK_MODE = 
		"Black pieces Computer/Human [C/H]";;

	public ChessPreferences(IAbstractUIPlatformFactory current_ui_factory) {
		this.ui_factory = current_ui_factory;
		
		IDialog dialog = ui_factory.createIDialog();
		
		dialog.addQuestions(Q_BLACK_MODE, this);
		dialog.addQuestions(Q_WHITE_MODE, this);
		
		dialog.display();
	}

	@Override
	public int getNumOfPlayers() {
		return player_types.size();
	}

	public Class<? extends IChessPlayer> getPlayerType(int index) {
		return player_types.get(index);
	}

	@Override
	public boolean isValid(String question, String answer) {
		if (answer.equals("C")){
			player_types.add(ChessComputerPlayer.class);
			return true;
		}else if (answer.equals("H")){
			player_types.add(ChessHumanPlayer.class);
			return true;
		}
		return false;
	}

}
